package org.wsdltools.profiles.wsi;

import org.custommonkey.xmlunit.Diff;
import org.custommonkey.xmlunit.Transform;
import org.custommonkey.xmlunit.XMLTestCase;
import org.custommonkey.xmlunit.XMLUnit;

import java.io.InputStreamReader;
import java.nio.charset.Charset;

import org.w3c.dom.Document;

import org.wsdltools.common.model.MEPEnum;
import org.wsdltools.common.model.Repository;
import org.wsdltools.common.model.ProfileEnum;
import org.wsdltools.common.model.ServiceInteraction;
import org.wsdltools.profiles.wsi.WSDLGenerator;

import groovy.util.GroovyTestCase;

class WSDLGeneratorTest extends GroovyTestCase {
	
	public void testGenerateWSIBP11_WSDL() {
		XMLUnit.setIgnoreWhitespace(true)
		String wsdlPath = "/org/wsdltools/profiles/wsi/RegisterMedicalCertificateInteraction_1.0_WSIBP11.wsdl"
		InputStream noBiDirInOutWSDL = getClass().getResourceAsStream(wsdlPath)
		Document myExpectedWSDL = XMLUnit.buildDocument(XMLUnit.getControlParser(), new InputStreamReader(noBiDirInOutWSDL, Charset.forName("UTF-8")))
		
		Repository rep = new Repository();
		rep.addServiceInteraction( "other", "insuranceprocess", "healthreporting", 1, 0, "RegisterMedicalCertificate", "Submission of medical health reports to the Swedish social insurance institutions",null, false, MEPEnum.InOut, ProfileEnum.WSIBP11);
		ServiceInteraction si = rep.getServiceInteraction("RegisterMedicalCertificate","other", "insuranceprocess", "healthreporting", 1, 0)
		
		String generatedWSDLString = new WSDLGenerator().generateWSDL(si)
		Document generatedWSDL = XMLUnit.buildDocument(XMLUnit.getControlParser(), new StringReader(generatedWSDLString))
		
		Diff myDiff = new Diff(myExpectedWSDL, generatedWSDL);
		assertTrue("WSDL not generated as expected:" + myDiff, myDiff.similar());
	}
}
